package util.tree;

public class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    TreeNode(int x) {
        val = x;
    }

    @Override
    public String toString() {
        String s = String.valueOf(val);
        if (left != null && right != null) {
            s = s + "->" + left.toString() + "->" + right.toString();
        } else if (left != null) {
            s = s + "->" + left.toString();
        } else if (right != null) {
            s = s + "->" + right.toString();
        }
        return s;
    }
}
